home *** CD-ROM | disk | FTP | other *** search
/ Merciful 5 / Merciful - Disc 5.iso / software / l / lightwavev5.0rcd.lha / plugins / EQUATION.DOC < prev    next >
Encoding:
Text File  |  1997-02-26  |  5.9 KB  |  160 lines

  1. Plugin: ExpressEval  (equation .p)    
  2. Version: 1.0      Fri May 13 1995
  3. Arithmetic expression evaluator for plugins
  4. by Will Menninger,  Arnie Cachelin
  5.  
  6. Module: Equation
  7. Class: Global
  8.  
  9. Equation is a plugin which provides expression evaluation services to other plugins. 
  10.  
  11. Equation.p is an arithmetic expression evaluator which converts a string containing a valid mathematical 
  12. equation into its floating point value.  It is based on Eval113, a command-line-based expression evaluator
  13. which is Copyright (C) 1993  Will Menninger and has been put into public distribution under the GNU public license agreement.
  14. This derivative software is also covered by this license, I have made minor modifications 
  15. to the source, and added several small glue modules to make this code into a Lightwave3D plug-in.  
  16. The complete source is freely available.
  17.                                                                          
  18. Equation.p is a global-class plug-in module.  This means that its functions are only available to other 
  19. plug-ins, not to end users.  To call Equation.p from a plug-in file, you must first get access to its 
  20. functions by calling the global function with the name for the plug-in service, in this case "ExpressEval".
  21. If the plug-in is loaded in LW, the global function will return the address of an Evaluator structure, 
  22. which has pointers to all the available functions.  The definitions for this and other necessary structures
  23. are in the file lweval.h, which must be #included in your source.
  24.  
  25. The Evaluator structure has the following elements:
  26.  
  27. int MaxInput
  28.     This number is the length of the largest equation string the functions bellow will accept.
  29.  
  30. double StringValue(char *eq)
  31.     This function evaluates the given equation and returns its value.
  32.  
  33. double ValueXYZT(char *eq, double X, double Y, double Z, double T)
  34.     This function returns the value for the given equation after setting the internal variables 'x', 
  35. 'y', 'z', and 't' to the input values in X,Y,Z and T.  The equation may contain references to none, any, 
  36. or all of the variables 'x', 'y', 'z', and 't'.
  37.  
  38. double Value(char *eq, int argc, ev_arg *argv)
  39.     This function returns the value for the given equation after setting internal variables listed in 
  40. the input array of ev_arg structures (argv).  The number of args in the array is specified in argc.  The 
  41. ev_arg structure is just a variable name (1 lowercase character), and a value for that variable.
  42.  
  43. The following built-in functions are supported by the evaluator:
  44.  
  45. abs(x)        absolute value
  46. acos(x)        arccosine, return value in radians
  47. acosh(x)    inverse hyperbolic cosine
  48. asin(x)        arcsine, return value in radians
  49. asinh(x)    inverse hyperbolic sine
  50. atan(x)        arctangent, return value in radians
  51. atan2(y,x)    arctangent of y/x, return value in radians
  52. atanh(x)    inverse hyperbolic tangent
  53. bessi(m,x)    bessel function Im(x)
  54. bessj(m,x)    bessel function Jm(x)
  55. bessk(m,x)    bessel function Km(x)
  56. ceil(x)        round up
  57. cos(x)        cosine, x in radians
  58. cosh(x)        hyperbolic cosine
  59. dbessi(m,x)    derivative of bessel function:  Im'(x)
  60. dbessj(m,x)    derivative of bessel function:  Jm'(x)
  61. dbessk(m,x)    derivative of bessel function:  Km'(x)
  62. djroot(m,n    nth non-zero root of Jm'(x)
  63. exp(x)        e (2.718..) raised to the power of x
  64. fact(n)        factorial (n!)
  65. floor(x)    round down
  66. jroot(m,n)    nth non-zero root of Jm(x)
  67. ln(x)        natural logarithm (base e)
  68. log(x)        logarithm to the base 10
  69. sgn(x)        -1 if x<0, 0 if x=0, +1 if x>0
  70. sin(x)        sine, x in radians
  71. sinh(x)        hyperbolic sine
  72. sqrt(x)        squareroot
  73. tan(x)        tangent, x in radians
  74. tanh(x)        hyperbolic tangent
  75. rand(x)       random value between 0.0 and 1.0, int part of x is seed
  76. noise(x,y,z)    fractal noise             
  77. ifeq(a,b,t,f)   if a=b then t else f
  78. iflt(a,b,t,f)   if a<b then t else f
  79. ifgt(a,b,t,f)   if a>b then t else f
  80. iflte(a,b,t,f)  if a<=b then t else f
  81. ifgte(a,b,t,f)  if a>=b then t else f 
  82.  
  83. Here are the constants available (and their values):
  84. _acres_per_sq_km                    247.1
  85. _air_density                    1.293
  86. _air_mol_mass                    .02897
  87. _atm_per_psi                    .06804
  88. _avagadro                    6.0220e23
  89. _boltzmann                    1.3807e-23
  90. _c                    2.997925e8
  91. _cm_per_in                    2.54
  92. _coulomb_const                    8.98755e9
  93. _deg_per_rad                    57.2958
  94. _earth_esc_spd                    1.12e4
  95. _earth_grav                    9.80665
  96. _earth_mass                    5.98e24
  97. _earth_radius                    6.37e6
  98. _earth_to_moon                    3.844e8
  99. _earth_to_sun                    1.496e11
  100. _eps0                    8.85419e-12
  101. _erg_per_joule                    1e7
  102. _eulers_const                    .57721566490153286061
  103. _ft_per_m                    3.280839895
  104. _g                    6.672e-11
  105. _gas_const                    8.314
  106. _gauss_per_tesla                    1e4
  107. _gm_per_oz                    28.34952313
  108. _golden_ratio                    1.6180339887498948482
  109. _h                    6.6262e-34
  110. _hbar                    1.05459e-34
  111. _joule_per_btu                    1054.35
  112. _joule_per_cal                    4.184
  113. _joule_per_ftlb                    1.356
  114. _joule_per_kwh                    3.6e6
  115. _kg_per_slug                    14.59
  116. _km_per_mi                    1.609344
  117. _knots_per_mph                    .86897624
  118. _lbs_per_kg                    2.204622622
  119. _lit_per_gal                    3.785411784
  120. _me                    9.1095e-31
  121. _mn                    1.67495e-27
  122. _moon_grav                    1.62
  123. _moon_mass                    7.35e22
  124. _moon_period                    2360448.
  125. _moon_radius                    1.738e6
  126. _mp                    1.67265e-27
  127. _mu0                    1.256637e-6
  128. _oz_per_gal                    128.
  129. _pasc_per_atm                    101325.
  130. _pasc_per_psi                    6895.
  131. _pasc_per_torr                    133.32
  132. _pi                    3.14159265358979323846
  133. _qe                    1.60219e-19
  134. _solar_const                    1350.
  135. _speed_sound                    331.
  136. _sun_mass                    1.99e30
  137. _sun_radius                    6.96e8
  138. _watts_per_hp                    745.712
  139. _zero_deg_cels                    273.15
  140.  
  141. Here is lweval.h (for your convenience...):
  142.  
  143. /* lweval.h -- Header for Global Equation.p, an expression evaluator */
  144. /* Wed Feb 15 00:11:45 1995 */
  145. /* Fri May 13 1995 */
  146.  
  147. typedef struct {
  148.     char        *symbol;
  149.     double    value;
  150. } ev_arg;
  151.  
  152. /* Returned by Global activation, for ID string "ExpressEval" */
  153. typedef    struct st_Evaluator {
  154.     int            MaxInput;                                                /* Read-only, longest string accepted by f'ns below... */
  155.     double    (*StringValue)(char *);                     /* Return Expression value */
  156.     double    (*ValueXYZT)(char *,double,double,double,double);            /* Return Expression value with var.s 'x', 'y', 'z', and 't' filled by doubles */
  157.     double    (*Value)(char *,int, ev_arg *);                    /*    Return expression with n args */
  158. } Evaluator;
  159.  
  160.